//
//  DecatilViewController.m
//  庐山通
//
//  Created by zcj on 15-10-30.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "DecatilViewController.h"
#import "SelectFindHttp.h"
#import "TravelDecatil.h"
#import "TravelDecatilFrame.h"
#import "DecaticTableViewCell.h"
#import <UIKit/UIKit.h>
#import "Grouble.h"


#define DecatilURL @"https://api.deyi.com/thread/view/?tid=5958033&page=1&perpage=20&ver=5&device=android&noimg=1&hash=2c214fd00c9de0a6b6a69369b1ed695a5cecdc2b"

@interface DecatilViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray * decaticFrame;
@property (nonatomic,weak)UITableView * myTableView;

@end

@implementation DecatilViewController
- (NSMutableArray *)decaticFrame
{
    if (_decaticFrame == nil) {
        _decaticFrame = [[NSMutableArray alloc]init];
    }
    return _decaticFrame;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavBar];
    [self createTableView];
    [self getLoadData];
    // Do any additional setup after loading the view.
}

- (void)getLoadData
{
    [MBProgressHUD showMessage:@"正在加载"];
    [SelectFindHttp postWirhUrl:DecatilURL parms:nil success:^(id json) {
       
       // ZCJLog(@"%@",json);
        //NSArray * tempArray = ;
        NSArray * myDataFrame = [TravelDecatil objectArrayWithKeyValuesArray:json[@"posts"]];
        //[myDataFrame removeob]
        int i = 0;
        for (TravelDecatil * travel in myDataFrame) {
            if (i > 0) {
                TravelDecatilFrame * travleDataFrame = [[TravelDecatilFrame alloc]init];
                
                travleDataFrame.travelDecatl = travel;
                
                [self.decaticFrame addObject:travleDataFrame];
            }
            i ++;
        }
        [self.myTableView reloadData];
        [MBProgressHUD hideHUD];
        [MBProgressHUD showSuccess:@"加载成功"];
        
    } failture:^(id error) {
         [MBProgressHUD showError:@"加载失败"];
        [MBProgressHUD hideHUD];
    }];

}
- (void)setNavBar
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancle)];
    
    self.title = @"详细信息";
    
}
- (void)cancle
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)createTableView
{
    UITableView * myTableView = [[UITableView alloc]initWithFrame:self.view.bounds];
    myTableView.backgroundColor = [UIColor whiteColor];
    
    myTableView.dataSource = self;
    myTableView.delegate = self;
    [self.view addSubview:myTableView];
    self.myTableView = myTableView;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.decaticFrame.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DecaticTableViewCell * cell = [DecaticTableViewCell DecaticTableViewCell:tableView];
    TravelDecatilFrame * dataFrame = self.decaticFrame[indexPath.row];
    NSLog(@"%@",dataFrame);
    cell.myDataFrame = dataFrame;
   
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TravelDecatilFrame * cellHs = self.decaticFrame[indexPath.row];
    //cellHs.
    //cellHs.DataFrameItem = cellHs;
    return cellHs.cellH;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
